home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Mail / pine3.92 / pico / main.c < prev    next >
C/C++ Source or Header  |  1996-03-14  |  10KB  |  401 lines

  1. #if    !defined(lint) && !defined(DOS)
  2. static char rcsid[] = "$Id: main.c,v 4.37 1996/03/15 07:41:11 hubert Exp $";
  3. #endif
  4. /*
  5.  * Program:    Main stand-alone Pine Composer routines
  6.  *
  7.  *
  8.  * Michael Seibel
  9.  * Networks and Distributed Computing
  10.  * Computing and Communications
  11.  * University of Washington
  12.  * Administration Builiding, AG-44
  13.  * Seattle, Washington, 98195, USA
  14.  * Internet: mikes@cac.washington.edu
  15.  *
  16.  * Please address all bugs and comments to "pine-bugs@cac.washington.edu"
  17.  *
  18.  *
  19.  * Pine and Pico are registered trademarks of the University of Washington.
  20.  * No commercial use of these trademarks may be made without prior written
  21.  * permission of the University of Washington.
  22.  * 
  23.  * Pine, Pico, and Pilot software and its included text are Copyright
  24.  * 1989-1996 by the University of Washington.
  25.  * 
  26.  * The full text of our legal notices is contained in the file called
  27.  * CPYRIGHT, included with this distribution.
  28.  *
  29.  *
  30.  * WEEMACS/PICO NOTES:
  31.  *
  32.  * 08 Jan 92 - removed PINE defines to simplify compiling
  33.  *
  34.  * 08 Apr 92 - removed PINE stub calls
  35.  *
  36.  */
  37.  
  38. #include        <stdio.h>
  39. #include    <setjmp.h>
  40. #include    "osdep.h"    /* operating system dependent includes */
  41. #include    "pico.h"    /* pine composer definitions */
  42. #include        "estruct.h"    /* global structures and defines */
  43. #include    "efunc.h"    /* function declarations and sans name table */
  44. #include    "edef.h"    /* global definitions */
  45.  
  46.  
  47. /*
  48.  * Useful internal prototypes
  49.  */
  50. #ifdef    _WINDOWS
  51. int    pico_file_drop(int, int, char *);
  52. #endif
  53.  
  54. /*
  55.  * this isn't defined in the library, because it's a pine global
  56.  * which we use for GetKey's timeout
  57.  */
  58. int    timeoutset = 0;
  59.  
  60. /*
  61.  * function key mappings
  62.  */
  63. static int fkm[12][2] = {
  64.     { F1,  (CTRL|'G')},
  65.     { F2,  (CTRL|'X')},
  66.     { F3,  (CTRL|'O')},
  67.     { F4,  (CTRL|'J')},
  68.     { F5,  (CTRL|'R')},
  69.     { F6,  (CTRL|'W')},
  70.     { F7,  (CTRL|'Y')},
  71.     { F8,  (CTRL|'V')},
  72.     { F9,  (CTRL|'K')},
  73.     { F10, (CTRL|'U')},
  74.     { F11, (CTRL|'C')},
  75. #ifdef    SPELLER
  76.     { F12, (CTRL|'T')}
  77. #else
  78.     { F12, (CTRL|'D')}
  79. #endif
  80. };
  81.  
  82.  
  83. /*
  84.  * main standalone pico routine
  85.  */
  86. #ifdef _WINDOWS
  87. app_main (argc, argv)
  88. #else
  89. main(argc, argv)
  90. #endif
  91. char    *argv[];
  92. {
  93.     register int    c;
  94.     register int    f;
  95.     register int    n;
  96.     register BUFFER *bp;
  97.     register int    carg;        /* current arg to scan         */
  98.     int         viewflag = FALSE;        /* are we starting in view mode?*/
  99.     int         starton = 0;        /* where's dot to begin with?    */
  100.     char     bname[NBUFN];        /* buffer name of file to read    */
  101.     char    *clerr = NULL;        /* garbage on command line    */
  102.  
  103.     timeout = 600;
  104.     Pmaster = NULL;            /* turn OFF composer functionality */
  105.     km_popped = 0;
  106.     opertree[0]     = '\0';
  107.     opertree[NLINE] = '\0';
  108.  
  109.     /*
  110.      * Read command line flags before initializing, otherwise, we never
  111.      * know to init for f_keys...
  112.      */
  113.     carg = 1;
  114.     while(carg < argc){
  115.     if(argv[carg][0] == '-'){
  116.         switch(argv[carg][1]){
  117.           case 'v':            /* -v for View File */
  118.           case 'V':
  119.         viewflag = !viewflag;
  120.         break;
  121.           case 'e':            /* file name completion */
  122.         gmode ^= MDCMPLT;
  123.         break;
  124.           case 'k':            /* kill from dot */
  125.         gmode ^= MDDTKILL;
  126.         break;
  127.           case 'g':            /* show-cursor in file browser */
  128.         gmode ^= MDSHOCUR;
  129.         break;
  130.           case 'm':            /* turn on mouse support */
  131.         gmode ^= MDMOUSE;
  132.         break;
  133.           case 'x':            /* suppress keyhelp */
  134.         sup_keyhelp = !sup_keyhelp;
  135.         break;
  136.           case 'd':            /* -d for rebind delete key */
  137.         bindtokey(0x7f, forwdel);
  138.         break;
  139.           case 'f':            /* -f for function key use */
  140.         gmode ^= MDFKEY;
  141.         break;
  142.           case 'r':            /* set fill column */
  143.         if(argv[carg][2] != '\0')
  144.           if((userfillcol = atoi(&argv[carg][2])) < 1)
  145.             userfillcol = 72;
  146.         break;
  147.           case 'n':            /* -n for new mail notification */
  148.         timeoutset = 1;
  149.         timeout = 180;
  150.         if(argv[carg][2] != '\0')
  151.           if((timeout = atoi(&argv[carg][2])) < 30)
  152.             timeout = 180;
  153.         break;
  154.           case 's' :
  155.         if(argv[carg+1] && argv[carg+1][0] && argv[carg+1][0] != '-')
  156.           alt_speller = argv[++carg];
  157.         /* BUG: should gripe if test fails */
  158.         break;
  159.           case 't':            /* special shutdown mode */
  160.         gmode ^= MDTOOL;
  161.         rebindfunc(wquit, quickexit);
  162.         break;
  163.           case 'o' :        /* operating tree */
  164.         if(argv[carg+1] && argv[carg+1][0] && argv[carg+1][0] != '-'){
  165.             strncpy(opertree, argv[++carg], NLINE);
  166.             gmode ^= MDTREE;
  167.         }
  168.         else{
  169.             printf("Missing or empty argument to -o flag isn't allowed\n");
  170.             exit(1);
  171.         }
  172.         break;
  173.           case 'z':            /* -z to suspend */
  174.         gmode ^= MDSSPD;
  175.         break;
  176.           case 'w':            /* -w turn off word wrap */
  177.         gmode ^= MDWRAP;
  178.         break;
  179. #if    defined(DOS) || defined(OS2)
  180.           case 'c':            /* -c[nr][fb] colors */
  181.         if(carg + 1 < argc){
  182.             if(argv[carg][2] == 'n'){
  183.             if(argv[carg][3] == 'f')
  184.               pico_nfcolor(argv[++carg]);
  185.             else if(argv[carg][3] == 'b')
  186.               pico_nbcolor(argv[++carg]);
  187.             }
  188.             else if(argv[carg][2] == 'r'){
  189.             if(argv[carg][3] == 'f')
  190.               pico_rfcolor(argv[++carg]);
  191.             else if(argv[carg][3] == 'b')
  192.               pico_rbcolor(argv[++carg]);
  193.             }
  194.         }
  195.         else{
  196.             clerr = "insufficient args for \"-c\"";
  197.             break;
  198.         }
  199.         break;
  200. #endif
  201.           default:            /* huh? */
  202.         clerr = argv[carg];
  203.         break;
  204.         }
  205.         carg++;
  206.     }
  207.     else if(argv[carg][0] == '+'){    /* leading '+' is special */
  208.         starton = atoi(&argv[carg][1]);
  209.         carg++;
  210.     }
  211.     else                /* pick up file name later... */
  212.       break;
  213.     }
  214.  
  215.     if(!vtinit())            /* Displays.            */
  216.     exit(1);
  217.  
  218.     strcpy(bname, "main");        /* default buffer name */
  219.     edinit(bname);            /* Buffers, windows.   */
  220.  
  221.     update();                /* let the user know we are here */
  222.  
  223. #ifdef    _WINDOWS
  224.     mswin_allowpaste(MSWIN_PASTE_FULL);
  225.     mswin_setclosetext("Use the ^X command to exit Pico.");
  226.     mswin_setscrollcallback (pico_scroll_callback);
  227. #endif
  228.  
  229. #if    defined(TERMCAP) || defined(TERMINFO) || defined(VMS)
  230.     if(pico_kbesc == NULL){        /* will arrow keys work ? */
  231.     (*term.t_putchar)('\007');
  232.     emlwrite("Warning: keypad keys may non-functional", NULL);
  233.     }
  234. #endif    /* TERMCAP/TERMINFO/VMS */
  235.  
  236.     if(carg < argc){            /* Any file to edit? */
  237.  
  238.     makename(bname, argv[carg]);    /* set up a buffer for this file */
  239.  
  240.     bp = curbp;            /* read in first file */
  241.     makename(bname, argv[carg]);
  242.     strcpy(bp->b_bname, bname);
  243.     strcpy(bp->b_fname, argv[carg]);
  244.     if (readin(argv[carg], (viewflag==FALSE)) == ABORT) {
  245.         strcpy(bp->b_bname, "main");
  246.         strcpy(bp->b_fname, "");
  247.     }
  248.     bp->b_dotp = bp->b_linep;
  249.     bp->b_doto = 0;
  250.  
  251.     if (viewflag)            /* set the view mode */
  252.       bp->b_mode |= MDVIEW;
  253.     }
  254.  
  255.     /* setup to process commands */
  256.     lastflag = 0;            /* Fake last flags.     */
  257.     curbp->b_mode |= gmode;        /* and set default modes*/
  258.  
  259.     curwp->w_flag |= WFMODE;        /* and force an update    */
  260.  
  261.     if(timeoutset)
  262.       emlwrite("Checking for new mail every %D seconds", (void *)timeout);
  263.  
  264.     if(clerr){                /* post any errors on command line */
  265.     if(mpresf)            /* show earlier message though! */
  266.       sleep(2);
  267.     emlwrite("\007Unknown option: %s", clerr);
  268.     }
  269.  
  270.     forwline(0, starton - 1);        /* move dot to specified line */
  271.  
  272.     while(1){
  273.  
  274.     if(km_popped){
  275.         km_popped--;
  276.         if(km_popped == 0) /* cause bottom three lines to be repainted */
  277.           curwp->w_flag |= WFHARD;
  278.     }
  279.  
  280.     if(km_popped){  /* temporarily change to cause menu to be painted */
  281.         term.t_mrow = 2;
  282.         curwp->w_ntrows -= 2;
  283.         curwp->w_flag |= WFMODE;
  284.         movecursor(term.t_nrow-2, 0); /* clear status line, too */
  285.         peeol();
  286.     }
  287.  
  288.     update();            /* Fix up the screen    */
  289.     if(km_popped){
  290.         term.t_mrow = 0;
  291.         curwp->w_ntrows += 2;
  292.     }
  293.  
  294. #ifdef    MOUSE
  295. #ifdef  EX_MOUSE
  296.     /* New mouse function for real mouse text seletion. */
  297.     register_mfunc(mouse_in_pico, 2, 0, term.t_nrow - (term.t_mrow + 1),
  298.                term.t_ncol);
  299. #else
  300.     mouse_in_content(K_MOUSE, -1, -1, 0, 0);
  301.     register_mfunc(mouse_in_content, 2, 0, term.t_nrow - (term.t_mrow + 1),
  302.                term.t_ncol);
  303. #endif
  304. #endif
  305. #ifdef    _WINDOWS
  306.     mswin_setdndcallback (pico_file_drop);
  307. #endif
  308.     c = GetKey();
  309. #ifdef    MOUSE
  310. #ifdef  EX_MOUSE
  311.     clear_mfunc(mouse_in_pico);
  312. #else
  313.     clear_mfunc(mouse_in_content);
  314. #endif
  315. #endif
  316. #ifdef    _WINDOWS
  317.     mswin_cleardndcallback ();
  318. #endif
  319.  
  320.     if(timeoutset && (c == NODATA || time_to_check())){
  321.         if(pico_new_mail())
  322.           emlwrite("You may possibly have new mail.", NULL);
  323.     }
  324.  
  325.     if(km_popped)
  326.       switch(c){
  327.         case NODATA:
  328.         case (CTRL|'L'):
  329.           km_popped++;
  330.           break;
  331.         
  332.         default:
  333.           /* clear bottom three lines */
  334.           mlerase();
  335.           break;
  336.       }
  337.  
  338.     if(c == NODATA)
  339.       continue;
  340.  
  341.     if(mpresf){            /* erase message line? */
  342.         if(mpresf++ > MESSDELAY)
  343.           mlerase();
  344.     }
  345.  
  346.     f = FALSE;
  347.     n = 1;
  348.  
  349. #ifdef    MOUSE
  350.     clear_mfunc(mouse_in_content);
  351. #endif
  352.                     /* Do it.               */
  353.     execute(normalize_cmd(c, fkm, 1), f, n);
  354.     }
  355. }
  356.  
  357.  
  358. #ifdef    _WINDOWS
  359. /*
  360.  *
  361.  */
  362. int
  363. pico_file_drop(x, y, filename)
  364.     int   x, y;
  365.     char *filename;
  366. {
  367.     /*
  368.      * if current buffer is unchanged
  369.      * *or* "new buffer" and no current text
  370.      */
  371.     if(((curwp->w_bufp->b_flag & BFCHG) == 0)
  372.        || (curwp->w_bufp->b_fname[0] == '\0'
  373.        && curwp->w_bufp->b_linep == lforw(curwp->w_bufp->b_linep)
  374.        && curwp->w_doto == 0)){
  375.     register BUFFER *bp = curwp->w_bufp;
  376.     char     bname[NBUFN];
  377.  
  378.     makename(bname, filename);
  379.     strcpy(bp->b_bname, bname);
  380.     strcpy(bp->b_fname, filename);
  381.     bp->b_flag &= ~BFCHG;    /* turn off change bit */
  382.     if (readin(filename, 1) == ABORT) {
  383.         strcpy(bp->b_bname, "");
  384.         strcpy(bp->b_fname, "");
  385.     }
  386.     bp->b_dotp = bp->b_linep;
  387.     bp->b_doto = 0;
  388.     }
  389.     else{
  390.     ifile(filename);
  391.     curwp->w_flag |= WFHARD;
  392.     update();
  393.     emlwrite("Inserted dropped file \"%s\"", filename);
  394.     }
  395.  
  396.     curwp->w_flag |= WFHARD;
  397.     update();            /* restore cursor */
  398.     return(1);
  399. }
  400. #endif
  401.